package trystero.lib.http.hc;

import java.io.InputStream;
import java.io.IOException;
import org.apache.http.HttpEntity;

public class EntityInputStream extends InputStream
{
   HttpEntity entity;
   InputStream input;

   EntityInputStream(HttpEntity entity)
   {
      this.entity = entity;
      try
      {
         this.input = entity.getContent();
      }
      catch(Exception e)
      {
      }
   }

   public int read() throws IOException
   {
      if(input != null)
         return input.read();
      else
	 throw new IOException();
   }

   public void close() throws IOException
   {
      super.close();
      entity.consumeContent(); 
   }
}
